package com.fatdetection.demo.controller;

import com.fatdetection.demo.annotation.AuthAdmin;
import com.fatdetection.demo.annotation.AuthOperator;
import com.fatdetection.demo.bean.Relation;
import com.fatdetection.demo.service.RelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/relation")
@RestController
@AuthAdmin
@AuthOperator
public class RelationController {
    @Autowired
    RelationService relationService;

    @GetMapping("/add")
    public Boolean insertRelation(Relation relation){
        Relation relation1 = new Relation();
        relation1.setProjectName("测试项目1");
        relation1.setSchoolName("测试学校1");
        return relationService.insertRelation(relation1);
    }

    @GetMapping("/del/{id}")
    public Boolean delRelation(@PathVariable("id")Integer id){
        return relationService.delRelation(id);
    }

    @GetMapping("/update")
    public Boolean updateRelation(Relation relation){
        Relation relation1 = relationService.findById(2);
        relation1.setSchoolName("已修改");
        relation1.setProjectName("已修改");
        return relationService.updateRelation(relation1);
    }

    @GetMapping("/findAll")
    public List<Relation> findAll(){
        List<Relation> list = relationService.findAll();
        return list;
    }

    @GetMapping("/findBySchool/{schoolName}")
    public List<Relation> findBySchool(@PathVariable("schoolName") String schoolName){
        List<Relation> list = relationService.findBySchool(schoolName);
        return list;
    }


    @GetMapping("/findByProj/{projectName}")
    public List<Relation> findByProj(@PathVariable("projectName") String projectName){
        List<Relation> list = relationService.findByProj(projectName);
        return list;
    }
}
